package com.example.demo;

import org.springframework.beans.factory.annotation.Value;

import javax.xml.transform.Source;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class Test {

    private static final int _1MB = 1024 * 1024;

    @Value("${svcUserCode}")
    private String svcUserCode;

    public static void main(String args[]) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
//        extracted();

//        testHandlePromotion();

        testFor();
    }

    private static void extracted() throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        System.out.println(User.class.getName());
        Class<?> userClass = Class.forName(User.class.getName());
        Constructor<?> constructor = userClass.getConstructor(String.class);
        Object zhangsan = constructor.newInstance("zhangsan");
        Method setAll = userClass.getMethod("setAll", String.class,String.class,int.class);
        Object invoke = setAll.invoke(zhangsan, "李四","老罗",24);

        Method hashCode = userClass.getMethod("hashCode", null);
        System.out.println(hashCode.invoke(zhangsan, null));
    }

    public static void testHandlePromotion(){
        byte[] allocation1,allocation2,allocation3,allocation4;
        allocation1 = new byte[1 * _1MB];
        allocation2 = new byte[1 * _1MB];
        allocation3 = new byte[1 * _1MB];
        allocation4 = new byte[4 * _1MB -100];
    }
    public static void testS() {

        String str1 = "abc";
        String str2 = new String("abc");
        System.out.println(str1 == str2);

        String str3 = new String("abc");
        System.out.println(str3 == str2);

        String str4 = "a" + "b";
        System.out.println(str4 == "ab");

        final String s = "a";
        String str5 = s + "b";
        System.out.println(str5 == "ab");

        String s1 = "a";
        String s2 = "b";
        String str6 = s1 + s2;
        System.out.println(str6 == "ab");
//
//        String str7 = "abc".substring(0,2);
//        System.out.println(str7 == "ab");
//
//        String str8 = "abc".toUpperCase();
//        System.out.println(str8 == "ABC");
//
//
//        String s5 = "a";
//        String s6 = "abc";
//        String s7 = s5 + "bc";
//        System.out.println(s6 == s7.intern());
//
//        String f2 = "java1";
//        String f = new String("ja") + new String("va1"); //f
//        System.out.println(f.intern() == f);
//        System.out.println(f.intern() == f2);
    }

    private static void testFor(){
        String strA = "IsCity||123123";
        String strB = "||123123";
        String strC = "";
        String strD = "IsCity";

        System.out.println(strA.split("\\|\\|")[0]+"____"+strA.split("\\|\\|")[1]);
        System.out.println(strB.split("\\|\\|")[0]+"____"+strB.split("\\|\\|")[1]);
        System.out.println(strC.split("\\|\\|") == null);
        System.out.println();
        String[] split = strD.split("\\|\\|");
        int length = split.length;
        System.out.println(strD.split("\\|\\|").toString());



    }

}
